package com.ease.common.vo;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;

import com.ease.common.util.Detect;
import com.ease.common.vo.editor.EndpointEditor;

/**
 * 
 * @author nathanleewei
 * 
 */
public class InetSocketAddressList extends ArrayList<InetSocketAddress> {

	/**
	 *
	 */
	private static final long serialVersionUID = 2512670238202706123L;

	private String servers;

	/**
	 * change 192.168.0.124:11211 192.168.0.125:11211 into InetSocketAddress list
	 */
	private void init() {
		if (null != this.servers) {
			EndpointEditor endpointEditor = new EndpointEditor();
			endpointEditor.setAsText(this.servers);
			List<Endpoint> endpoints = endpointEditor.getEndpoints();
			if (Detect.notEmpty(endpoints)) {
				InetSocketAddress inetSocketAddress = null;
				for (Endpoint endpoint : endpoints) {
					inetSocketAddress = new InetSocketAddress(endpoint.getAddress(), endpoint.getPort());
					this.add(inetSocketAddress);
				}
			}
		}
	}

	/**
	 * @param servers
	 *            the servers to set
	 */
	public void setServers(String servers) {
		this.servers = servers;
		init();
	}

	/**
	 * @return the servers
	 */
	public String getServers() {
		return servers;
	}

}
